package com.xnewtech.xplatform.swan.model.enums;

import lombok.Getter;

/**
 * 启用禁用标识
 *
 * @author xnew
 * @Date 2018/7/24 下午5:31
 */
@Getter
public enum StatusEnum {

    ENABLE(1, "启用"),

    DISABLE(2, "禁用");

    private final Integer code;
    private final String desc;

    StatusEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static String getNameByCode(Integer code) {
        if (null != code) {
            for (StatusEnum enumItem : StatusEnum.values()) {
                if (enumItem.getCode().equals(code)) {
                    return enumItem.getDesc();
                }
            }
        }
        return "";
    }

    public static StatusEnum toEnum(Integer code) {
        if (null != code) {
            for (StatusEnum e : StatusEnum.values()) {
                if (e.getCode().equals(code)) {
                    return e;
                }
            }
        }
        return null;
    }

}
